export function getUrlParam(name) {
  let reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)')
  let result = window.location.search.substr(1).match(reg)
  return result ? decodeURIComponent(result[2]) : null
}

export const formValidator = {
  checkName (name) {
    if (!(/^[\u4E00-\u9FBF]{2,}$/).test(name)) {
      return '请输入正确的姓名'
    }
    return false
  },
  checkMobile (phone) {
    if (!(/^1[3,4,5,6,7,8,9][0-9]{9}$/).test(phone)) {
      return '输入正确手机号'
    }
    return false
  },
  checkCarNum (carNum) {
    if (!(/^[\u4e00-\u9fa5]{1}[A-Z]{1}[A-Z_0-9]{5}$/).test(carNum)) {
      return '输入正确车牌号'
    }
    return false
  },
  checkPassword(value) {
    if (value.length < 6) {
      return '请输入正确的密码'
    }
    return false
  },
  checkUserName(name){
    if (!(/^[a-zA-Z0-9_-]{4,16}$/).test(name)) {
      return '用户名格式不正确'
    }
    return false
  }
}
